/* Endless Code Copyright (C) 2009 Jingul,Kim
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
package ec.gfx.ui;

import ec.Result;
import ec.gfx.GL;
import ec.gfx.Scene;

/**
 * @since 2009
 * @version 1.0
 * @author <a href="mailto:jingul.kim@gmail.com">Jingul,Kim</a>
 */
public class Border extends Addition {
	private float thickness = 3f;
	
	private Header header;
	
	public Border(Header header) {
		this.header = header;
	}

	@Override
	public Result update(Scene scene) {
		return Result.OK;
	}

	@Override
	public Result now(Scene scene) {
		GL.lineWidth(thickness);
		
		// 원점 이동
		GL.translatef(0, header.h, 0);
		
		GL.color3f(0f, 0f, 1f);
		
		GL.begin(GL.GL_LINE_LOOP);
		GL.vertex2f(0f, 0f);
		GL.vertex2f(w, 0f);
		GL.vertex2f(w, -h);
		GL.vertex2f(0f, -h);
		GL.end();

		return Result.OK;
	}
	
	@Override
	public void addNotify() {
		resize();
	}
	
	@Override
	protected void notifyResized() {
		resize();
	};
	
	private final void resize() {
		this.w = parent.w;
		this.h = parent.h + header.h;
	}
}
